package com.bootdo.wx.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.bootdo.common.config.Constant;
import com.bootdo.common.utils.*;
import com.bootdo.wx.dao.*;
import com.bootdo.wx.domain.*;
import com.bootdo.wx.dto.GoodsDto;
import com.bootdo.wx.service.GoodsGoodsService;
import com.bootdo.wx.service.GoodsImagesService;
import com.bootdo.wx.service.GoodsProductService;
import com.bootdo.wx.service.GoodsSpikeService;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.bootdo.common.utils.ShiroUtils.getUserId;

@Service
public class GoodsGoodsServiceImpl implements GoodsGoodsService {
	@Autowired
	private GoodsGoodsDao goodsGoodsDao;
	@Autowired
	private MemberUserDao memberUserDao;
	@Autowired
	private GoodsProductDao goodsProductDao;
	@Autowired
	private GoodsImagesService goodsImagesService;
	@Autowired
	private GoodsProductService goodsProductService;
	@Autowired
	private GoodsImagesDao goodsImagesDao;
	@Autowired
	private GoodsSpikeService goodsSpikeService;
	@Autowired
	private MemberFollowDao memberFollowDao;
	@Autowired
	private OrderComentDao orderComentDao;
	@Autowired
	private GoodsSpikeDao goodsSpikeDao;
	@Autowired
	private GoodsNineDao goodsNineDao;
	@Autowired
	private GoodsBargainDao goodsBargainDao;
	@Autowired
	private GoodsSpikeTimeDao goodsSpikeTimeDao;
	@Autowired
	private CmsContentDao cmsContentDao;
	@Autowired
	private GoodsTeamDao goodsTeamDao;
	@Autowired
	private GoodsUpgradeDao goodsUpgradeDao;
	@Autowired
	private MemberScoreDao memberScoreDao;
	@Autowired
	private MemberStockDao memberStockDao;
	@Autowired
	private MemberAddressDao memberAddressDao;
	@Autowired
	private ShopExpressMoneyDao shopExpressMoneyDao;
	@Autowired
	private GoodsLiveAppointmentDao goodsLiveAppointmentDao;

	/*
	 * @Autowired private ShopEstempService shopEstempService;
	 */
	/*
	 * @Autowired private OrderCommentService orderCommentService;
	 * 
	 * @Autowired private ShopShippingService shopShippingService;
	 */

	@Override
	public GoodsGoodsDO get(String id) {
		return goodsGoodsDao.get(id);
	}

	@Override
	public List<GoodsGoodsDO> list(Map<String, Object> map) {
		return goodsGoodsDao.list(map);
	}

	@Override
	public List<Map<String, Object>> queryAllForIdAndName(Map<String, Object> map) {
		return goodsGoodsDao.queryAllForIdAndName(map);
	}

	@Override
	public int count(Map<String, Object> map) {
		return goodsGoodsDao.count(map);
	}

	@Override
	public int save(GoodsGoodsDO goodsGoods) {
		return goodsGoodsDao.save(goodsGoods);
	}

	@Override
	public int update(GoodsGoodsDO goodsGoods) {
		return goodsGoodsDao.update(goodsGoods);
	}

	@Override
	public int remove(String id) {
		return goodsGoodsDao.remove(id);
	}

	@Override
	public int batchRemove(String[] ids) {
		return goodsGoodsDao.batchRemove(ids);
	}

	@Override
	public R findGoods(Map<String, Object> params) {
		if ("".equals(params.get("name").toString())) {
			return R.error("请输入要搜索的字段");
		}
		PageHelperUtils.page(params, MapUtil.getStr(params,"order"));
		// 搜索商品
		List<Map<String, Object>> goodsList = goodsGoodsDao.findByName(params);
		/*for (Map<String, Object> goodsMap : goodsList) {
			String imgurl = goodsMap.get("imgurl").toString();
			List<String> imgList = new ArrayList<String>();
			imgList.add(imgurl);
			goodsMap.remove("imgurl");
			goodsMap.put("imgList", imgList);

			int stock = (int) goodsMap.get("stock");
			int num_sale = (int) goodsMap.get("num_sale");
			int baiFenBi = (num_sale *100)/stock ;//百分比
			goodsMap.put("baiFenBi",baiFenBi);

		}*/
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goodsList);
		return R.ok().put("data", pageInfo);

	}

	@Override
	public R getHotList(Map<String, Object> map) {
		PageHelperUtils.page(map);
		List<Map<String, Object>> goods = goodsGoodsDao.getHotList(map);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goods);
		return R.ok().put("data", pageInfo);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public R add(GoodsGoodsDO goodsGoods, String products, String spec_values, String param_values, String images,
			String imagesDetail) {

		goodsGoods.setId(UuidUtil.get32UUID());
		goodsGoods.setParam(param_values);
		goodsGoods.setSpec(spec_values);
		goodsGoods.setCategory(0);
		// goodsGoods.setProp(prop_values);
		Date date = new Date();
		if (goodsGoods.getDisabled() == 0) {// 上架时间
			goodsGoods.setUpAt(date);
		}

		if (goodsGoods.getNumSale() == null) {
			goodsGoods.setNumSale(0);
		}
		if (goodsGoods.getIsvip() == null) {
			goodsGoods.setIsvip(0);
		}
		// 设置参数
		goodsGoods.setGmtCreate(date);
		goodsGoods.setNumComment(0);
		goodsGoods.setNumView(0);
		goodsGoods.setNumSaleWeek(0);
		goodsGoods.setDelFlag(Constant.DEFAULT_DEL_FLAG);
		goodsGoods.setUserIdCreate(getUserId());
		goodsGoods.setRecomSy(0);
		goodsGoods.setRecomXq(0);
		goodsGoods.setRecomGwc(0);
		goodsGoods.setIsHot(0);
		goodsGoods.setRecomSyt(0);
		goodsGoods.setCouponId("-1");
		if(goodsGoods.getCategory()>0&&null == goodsGoods.getSpikeEnd()){
			return R.error("结束时间不能为空");
		}
		goodsGoodsDao.save(goodsGoods);

		// 商品图片
		List<Map<String, Object>> imgArr = (List<Map<String, Object>>) JSON.parse(images);
		// 商品相册
		// HashMap<String,Object>[] imgArr = Json.fromJsonAsArray(NutMap.class,
		// images);
		if (imgArr != null) {
			String defaultImge = "";
			for (int i = 0; i < imgArr.size(); i++) {
				if (i == 0 || (boolean) imgArr.get(i).get("d"))
					defaultImge = imgArr.get(i).get("url").toString();
				GoodsImagesDO goodsImage = new GoodsImagesDO();
				goodsImage.setGoodsId(goodsGoods.getId());
				goodsImage.setLocation(i);
				goodsImage.setAddress(0);
				goodsImage.setImgurl(imgArr.get(i).get("url").toString());
				goodsImage.setId(UuidUtil.get32UUID());
				goodsImage.setGmtCreate(date);
				goodsImage.setUserIdCreate(getUserId());
				goodsImage.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				goodsImagesService.save(goodsImage);
			}
			goodsGoods.setImgurl(defaultImge);
			goodsGoodsDao.update(goodsGoods);
		}

		// 商品货品
		List<Map<String, Object>> productArr = (List<Map<String, Object>>) JSON.parse(products);
		// productArr
		// HashMap[] productArr = Json.fromJsonAsArray(HashMap.class, products);
		if (productArr != null) {
			if (goodsGoods.getHasSpec() == 1 && StringUtils.isBlank(productArr.get(0).get("sku").toString())) {
				// 如果没有启用规格，并且第一个货品SKU为null或空白字符则自动生成SKU
				productArr.get(0).put("sku", goodsProductService.getSkuPrefix());
			}
			for (int i = 0; i < productArr.size(); i++) {
				String name = "";
				String spec = productArr.get(i).get("spec").toString();
				GoodsProductDO product = new GoodsProductDO();
				product.setId(UuidUtil.get32UUID());
				product.setGoodsId(goodsGoods.getId());
				product.setLocation(i);
				product.setSpec(spec);
				product.setUnit(goodsGoods.getUnit());
				product.setIcon(goodsGoods.getImgurl());
				// 如果SKU为null或空白字符则自动生成SKU
				if (StringUtils.isBlank(productArr.get(i).get("sku").toString())) {
					product.setSku(goodsProductService.getSkuPrefix() + "-" + i);
				} else {
					product.setSku(productArr.get(i).get("sku").toString().toUpperCase());
				}
				// 通过规格获取名称
				StringBuffer bufName = new StringBuffer();
				if (spec.contains("*") && spec.contains(":")) {
					String[] str = StringUtils.split(spec, "*");
					for (String temp : str) {
						String[] s = StringUtils.split(temp, ":");
						// name += s[1] + " ";
						bufName.append(s[1] + " ");
					}
				} else if (spec.contains(":")) {
					String[] s = StringUtils.split(spec, ":");
					// name = s[1];
					bufName.append(s[1]);
				}
				name = bufName.toString();
				product.setName(name);
				Boolean isDefault = (boolean) productArr.get(i).get("isDefault");
				if (isDefault) {
					product.setIsDefault(1);
				} else {
					product.setIsDefault(0);
				}
				Boolean disabled = (boolean) productArr.get(i).get("disabled");
				if (disabled) {
					product.setDisabled(1);
				} else {
					product.setDisabled(0);
					// 上架时间
					product.setUpAt(date);
				}
				String stock = productArr.get(i).get("stock").toString().replace(" ", "");
				product.setStock(NumberUtils.toInt(stock, 0));
				product.setBuyMin(NumberUtils.toInt(productArr.get(i).get("buyMin").toString().replace(" ", ""), 0));
				product.setBuyMax(NumberUtils.toInt(productArr.get(i).get("buyMax").toString().replace(" ", ""), 0));
				product.setWeight(NumberUtils.toDouble(productArr.get(i).get("weight").toString().replace(" ", ""), 0));
				product.setPriceMarket(new BigDecimal(productArr.get(i).get("priceMarket").toString()));
				product.setPrice(new BigDecimal(productArr.get(i).get("price").toString()));

				  product.setPriceC(new
				  BigDecimal(("".equals(productArr.get(i).get("priceC"))||null==productArr.get(i).get("priceC"))?"0":productArr.get(i).get("priceC").toString()));
				  product.setPriceZ(new
				 BigDecimal(("".equals(productArr.get(i).get("priceZ"))||null==productArr.get(i).get("priceZ"))?"0":productArr.get(i).get("priceZ").toString()));
				  product.setPriceG(new BigDecimal(("".equals(productArr.get(i).get("priceG"))||null==productArr.get(i).get("priceG"))?"0":productArr.get(i).get("priceG").toString()));
				 if(product.getPriceC().compareTo(product.getPrice())>0){
				 	return R.error("团长价格必须小于等于用户价格");
				 }
				if(product.getPriceZ().compareTo(product.getPriceC())>0){
					return R.error("核心价格必须小于等于团长价格");
				}
				if(product.getPriceG().compareTo(product.getPriceZ())>0){
					return R.error("合伙人价格必须小于等于核心价格");
				}
				if (productArr.get(i).get("postFee")== null
						|| "".equals(productArr.get(i).get("postFee").toString())) {
					product.setPostFee(new BigDecimal("0.00"));
				} else {
					product.setPostFee(new BigDecimal(productArr.get(i).get("postFee").toString()));
				}
				  product.setRebateOne(new
				  BigDecimal(("".equals(productArr.get(i).get("rebateOne"))||null==productArr.get(i).get("rebateOne"))?"0":productArr.get(i).get("rebateOne").toString()));
				  product.setRebateTwo(new
				  BigDecimal(("".equals(productArr.get(i).get("rebateTwo"))||null==productArr.get(i).get("rebateTwo"))?"0":productArr.get(i).get("rebateTwo").toString()));
				// 设置默认参数
				product.setNumSale(0);
				product.setLocation(i);
				product.setUserIdCreate(getUserId());
				product.setGmtCreate(date);
				product.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				goodsProductService.save(product);
				// 把所有商品规格,都添加到仓库里,用户可以进货
				List<MemberUserDO> byLevelGt0 = memberUserDao.getByLevelGt0();
				if(byLevelGt0.size()>0){
					for (MemberUserDO memberUserDO : byLevelGt0) {
						Map<String, Object> productMap = new HashMap<>();
						productMap.put("delFlag", "0");
						productMap.put("goodsId", product.getGoodsId());
						productMap.put("productId", product.getId());
						productMap.put("userId", memberUserDO.getId());
						List<MemberStockDO> list2 = memberStockDao.list(productMap);
						if (list2.size() <= 0) {
							MemberStockDO memberStockDO = new MemberStockDO();
							memberStockDO.setCaAt(new Date());
							memberStockDO.setCause("添加新商品");
							memberStockDO.setDelFlag(0);
							memberStockDO.setGoodsId(product.getGoodsId());
							memberStockDO.setId(UUIDUtils.getUUID());
							memberStockDO.setProductId(product.getId());
							memberStockDO.setStock(0);
							memberStockDO.setUserId(memberUserDO.getId());
							memberStockDao.save(memberStockDO);
						}
					}
				}
				

			}
		}

		// 商品货品
		List<Map<String, Object>> imgDetailArr = (List<Map<String, Object>>) JSON.parse(imagesDetail);
		// 商品相册
		// HashMap<String,Object>[] imgArr = Json.fromJsonAsArray(NutMap.class,
		// images);
		if (imgDetailArr != null) {
			for (int i = 0; i < imgDetailArr.size(); i++) {
				GoodsImagesDO goodsImage = new GoodsImagesDO();
				goodsImage.setGoodsId(goodsGoods.getId());
				goodsImage.setLocation(i);
				goodsImage.setAddress(1);
				goodsImage.setImgurl(imgDetailArr.get(i).get("url").toString());
				goodsImage.setId(UuidUtil.get32UUID());
				goodsImage.setGmtCreate(date);
				goodsImage.setUserIdCreate(getUserId());
				goodsImage.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				goodsImagesService.save(goodsImage);
			}
		}

		
		/*
		 * ShopEstempDO estemp = new ShopEstempDO(); estemp.setAction("create");
		 * estemp.setGoodsId(goodsGoods.getId());
		 * estemp.setId(UuidUtil.get32UUID()); estemp.setOpBy(getUserId());
		 * estemp.setOpAt(date); estemp.setDelFlag(Constant.DEFAULT_DEL_FLAG);
		 * shopEstempService.save(estemp);
		 */
		return R.ok();

	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public R edit(GoodsGoodsDO goodsGoods, String products, String spec_values, String param_values, String images,
			String imagesDetail) {
		if (spec_values==null||spec_values.equals("[]")) {
			GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.get(goodsGoods.getId());
			goodsGoods.setSpec(goodsGoodsDO.getSpec());
		} else {
			goodsGoods.setSpec(spec_values);
		}
		if (param_values==null||param_values.equals("[]")) {
			GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.get(goodsGoods.getId());
			goodsGoods.setParam(goodsGoodsDO.getParam());
		} else {
			goodsGoods.setParam(param_values);
		}
		Date date = new Date();
		if(goodsGoods.getCategory()>0&&null ==goodsGoods.getSpikeEnd()){
			return R.error("结束时间不能为空");
		}
		goodsGoods.setGmtModified(date);
		goodsGoods.setUserIdCreate(getUserId());
		goodsGoodsDao.update(goodsGoods);
		// 删除商品相册信息
		goodsImagesService.removeByGoodsId(goodsGoods.getId());
		// 删除商品货品信息
		goodsProductService.removeByGoodsIdJ(goodsGoods.getId());
		// goodsProductService.removeByGoodsId(goodsGoods.getId());

		// 商品图片
		List<Map<String, Object>> imgArr = (List<Map<String, Object>>) JSON.parse(images);
		// 商品相册
		// HashMap<String,Object>[] imgArr = Json.fromJsonAsArray(NutMap.class,
		// images);
		if (imgArr != null) {
			String defaultImge = "";
			for (int i = 0; i < imgArr.size(); i++) {
				if (i == 0 || (boolean) imgArr.get(i).get("d"))
					defaultImge = imgArr.get(i).get("url").toString();
				GoodsImagesDO goodsImage = new GoodsImagesDO();
				goodsImage.setGoodsId(goodsGoods.getId());
				goodsImage.setLocation(i);
				goodsImage.setAddress(0);
				goodsImage.setImgurl(imgArr.get(i).get("url").toString());
				goodsImage.setId(UuidUtil.get32UUID());
				goodsImage.setGmtCreate(date);
				goodsImage.setUserIdCreate(getUserId());
				goodsImage.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				goodsImagesService.save(goodsImage);
			}
			goodsGoods.setImgurl(defaultImge);
			goodsGoodsDao.update(goodsGoods);
		}

		// 商品货品
		List<Map<String, Object>> productArr = (List<Map<String, Object>>) JSON.parse(products);
		// productArr
		// HashMap[] productArr = Json.fromJsonAsArray(HashMap.class, products);
		if (productArr != null) {
			if (goodsGoods.getHasSpec() == 1 && StringUtils.isBlank(productArr.get(0).get("sku").toString())) {
				// 如果没有启用规格，并且第一个货品SKU为null或空白字符则自动生成SKU
				productArr.get(0).put("sku", goodsProductService.getSkuPrefix());
			}
			for (int i = 0; i < productArr.size(); i++) {
				String productId = "";
				String name = "";
				String spec = productArr.get(i).get("spec").toString();
				GoodsProductDO product = new GoodsProductDO();
				if (productArr.get(i).containsKey("productId")) {

					productId = productArr.get(i).get("productId").toString();

				}

				product.setGoodsId(goodsGoods.getId());
				product.setLocation(i);
				product.setSpec(spec);
				product.setUnit(goodsGoods.getUnit());
				product.setIcon(goodsGoods.getImgurl());
				// 如果SKU为null或空白字符则自动生成SKU
				if (StringUtils.isBlank(productArr.get(i).get("sku").toString())) {
					product.setSku(goodsProductService.getSkuPrefix() + "-" + i);
				} else {
					product.setSku(productArr.get(i).get("sku").toString().toUpperCase());
					Map<String, Object> skuMap = new HashMap<>();
					skuMap.put("sku", product.getSku());
					List<GoodsProductDO> list = goodsProductService.list(skuMap);
					if (list.size() > 0) {
						productId = list.get(0).getId();
					}
				}
				// 通过规格获取名称
				StringBuffer bufName = new StringBuffer();
				if (spec.contains("*") && spec.contains(":")) {
					String[] str = StringUtils.split(spec, "*");
					for (String temp : str) {
						String[] s = StringUtils.split(temp, ":");
						// name += s[1] + " ";
						bufName.append(s[1] + " ");
					}
				} else if (spec.contains(":")) {
					String[] s = StringUtils.split(spec, ":");
					// name = s[1];
					bufName.append(s[1]);
				}
				name = bufName.toString();
				product.setName(name);
				Boolean isDefault = (boolean) productArr.get(i).get("isDefault");
				if (isDefault) {
					product.setIsDefault(1);
				} else {
					product.setIsDefault(0);
				}
				Boolean disabled = (boolean) productArr.get(i).get("disabled");
				if (disabled) {
					product.setDisabled(1);
				} else {
					product.setDisabled(0);
					// 上架时间
					product.setUpAt(date);
				}
				product.setStock(NumberUtils.toInt(productArr.get(i).get("stock").toString().replaceAll(" ", ""), 0));
				product.setBuyMin(NumberUtils.toInt(productArr.get(i).get("buyMin").toString().replaceAll(" ", ""), 1));
				product.setBuyMax(
						NumberUtils.toInt(productArr.get(i).get("buyMax").toString().replaceAll(" ", ""), 100));
				product.setWeight(
						NumberUtils.toDouble(productArr.get(i).get("weight").toString().replaceAll(" ", ""), 0));
				product.setPriceMarket(new BigDecimal(("".equals(productArr.get(i).get("priceMarket"))||null==productArr.get(i).get("priceMarket"))?"0":productArr.get(i).get("priceMarket").toString()));
				product.setPrice(new BigDecimal(("".equals(productArr.get(i).get("price"))||null==productArr.get(i).get("price"))?"0":productArr.get(i).get("price").toString()));

				  product.setPriceC(new
				  BigDecimal(("".equals(productArr.get(i).get("priceC"))||null==productArr.get(i).get("priceC"))?"0":productArr.get(i).get("priceC").toString()));
				  product.setPriceZ(new
				 BigDecimal(("".equals(productArr.get(i).get("priceZ"))||null==productArr.get(i).get("priceZ"))?"0":productArr.get(i).get("priceZ").toString()));
				  product.setPriceG(new
				  BigDecimal(("".equals(productArr.get(i).get("priceG"))||null==productArr.get(i).get("priceG"))?"0":productArr.get(i).get("priceG").toString()));
				if(product.getPriceC().compareTo(product.getPrice())>0){
					return R.error("团长价格必须小于等于用户价格");
				}
				if(product.getPriceZ().compareTo(product.getPriceC())>0){
					return R.error("核心价格必须小于等于团长价格");
				}
				if(product.getPriceG().compareTo(product.getPriceZ())>0){
					return R.error("合伙人价格必须小于等于核心价格");
				}
				if (null == productArr.get(i).get("postFee")
						|| "".equals(productArr.get(i).get("postFee"))) {
					product.setPostFee(new BigDecimal("0.00"));
				} else {
					product.setPostFee(new BigDecimal(productArr.get(i).get("postFee").toString()));
				}

				  product.setRebateOne(new
				  BigDecimal(("".equals(productArr.get(i).get("rebateOne"))||null==productArr.get(i).get("rebateOne"))?"0":productArr.get(i).get("rebateOne").toString()));
				  product.setRebateTwo(new
				  BigDecimal(("".equals(productArr.get(i).get("rebateTwo"))||null==productArr.get(i).get("rebateTwo"))?"0":productArr.get(i).get("rebateTwo").toString()));
				// 设置默认参数
				product.setNumSale(0);
				product.setLocation(i);
				product.setUserIdCreate(getUserId());
				product.setGmtCreate(date);
				product.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				if (StringUtils.isBlank(productId)) {
					product.setId(UuidUtil.get32UUID());
					goodsProductService.save(product);
				} else {
					product.setId(productId);
					int update = goodsProductService.update(product);
					System.out.println(update);
				}

				// 把所有商品规格,都添加到仓库里,用户可以进货
				List<MemberUserDO> byLevelGt0 = memberUserDao.getByLevelGt0();
				if(byLevelGt0.size()>0){
					for (MemberUserDO memberUserDO : byLevelGt0) {
						Map<String, Object> productMap = new HashMap<>();
						productMap.put("delFlag", "0");
						productMap.put("goodsId", product.getGoodsId());
						productMap.put("productId", product.getId());
						productMap.put("userId", memberUserDO.getId());
						List<MemberStockDO> list2 = memberStockDao.list(productMap);
						if (list2.size() <= 0) {
							MemberStockDO memberStockDO = new MemberStockDO();
							memberStockDO.setCaAt(new Date());
							memberStockDO.setCause("修改新商品");
							memberStockDO.setDelFlag(0);
							memberStockDO.setGoodsId(product.getGoodsId());
							memberStockDO.setId(UUIDUtils.getUUID());
							memberStockDO.setProductId(product.getId());
							memberStockDO.setStock(0);
							memberStockDO.setUserId(memberUserDO.getId());
							memberStockDao.save(memberStockDO);
						}
					}
				}
			}
		}

		// 商品货品
		List<Map<String, Object>> imgDetailArr = (List<Map<String, Object>>) JSON.parse(imagesDetail);
		// 商品相册
		// HashMap<String,Object>[] imgArr = Json.fromJsonAsArray(NutMap.class,
		// images);
		if (imgDetailArr != null) {
			for (int i = 0; i < imgDetailArr.size(); i++) {
				GoodsImagesDO goodsImage = new GoodsImagesDO();
				goodsImage.setGoodsId(goodsGoods.getId());
				goodsImage.setLocation(i);
				goodsImage.setAddress(1);
				goodsImage.setImgurl(imgDetailArr.get(i).get("url").toString());
				goodsImage.setId(UuidUtil.get32UUID());
				goodsImage.setGmtCreate(date);
				goodsImage.setUserIdCreate(getUserId());
				goodsImage.setDelFlag(Constant.DEFAULT_DEL_FLAG);
				goodsImagesService.save(goodsImage);
			}
		}
		/*
		 * ShopEstempDO estemp = new ShopEstempDO(); estemp.setAction("update");
		 * estemp.setGoodsId(goodsGoods.getId());
		 * estemp.setId(UUIDUtils.getUUID()); estemp.setOpBy(getUserId());
		 * estemp.setOpAt(date); estemp.setDelFlag(Constant.DEFAULT_DEL_FLAG);
		 * shopEstempService.save(estemp);
		 */
		return R.ok();
	}

	/**
	 * 根据分类查询商品列表
	 */
	@Override
	public R goodsListByClass(Map<String, Object> params) {
		/*
		 * String userId =
		 * com.bootdo.common.utils.StringUtils.getString(params.get("userId"));
		 * MemberUserDO memberUserDO = memberUserDao.get(userId);
		 */
		/*
		 * int level = 0; if (memberUserDO != null) { params.put("level",
		 * memberUserDO.getLevel()); level = memberUserDO.getLevel(); } else {
		 */
		/*
		 * params.put("level", 0); int level = 0;
		 */
		// }
		if ("".equals(params.get("order")) || StringUtils.isBlank(params.get("order").toString())) {
			PageHelperUtils.page(params, "gg.up_at", "desc");
		} else {
			PageHelperUtils.page(params, params.get("order").toString(), params.get("method").toString());
		}
		List<Map<String, Object>> goodsList = goodsGoodsDao.goodsListByClass(params);
		for (Map<String, Object> goodsMap : goodsList) {
			// int isvip = Integer.valueOf(goodsMap.get("isvip").toString());
			String imgurl = goodsMap.get("imgurl").toString();
			List<String> imgList = new ArrayList<String>();
			imgList.add(imgurl);
			goodsMap.remove("imgurl");
			goodsMap.put("imgList", imgList);
			Object price = goodsMap.get("price");
			/*
			 * Object price_c = goodsMap.get("price_c"); Object price_z =
			 * goodsMap.get("price_z"); Object price_g =
			 * goodsMap.get("price_g");
			 */
			goodsMap.put("minePrice", price);
			/*
			 * switch (level) { case 1 : goodsMap.put("minePrice",price_c);
			 * break; case 2 : goodsMap.put("minePrice",price_z); break; case 3
			 * : goodsMap.put("minePrice",price_g); break; default:
			 * goodsMap.put("minePrice",price); } }
			 */
		}

		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goodsList);
		return R.ok().put("data", pageInfo);
	}

	/**
	 * 普通商品详情页
	 */
	@Override
	public R getDetail(Map<String, Object> params) {
		String goodsId = params.get("goodsId").toString();
		String userId = params.get("userId").toString();
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		//GoodsProductDO isDefaultByGoods = goodsProductDao.getIsDefaultByGoods(goodsId);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		GoodsProductDO isDefaultByGoods = goodsProductDao.getIsDefaultByGoods(goodsId);
		if(isDefaultByGoods.getStock()<=0){
			return R.ok(200,"商品库存不足,无法查看");
		}
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());

		//goodsDto.setNumSale(goodsGoodsDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(goodsGoodsDO.getCategory());

		goodsDto.setCopywriting(goodsGoodsDO.getCopywriting());
		//goodsDto.setAllNumber(goodsGoodsDO.getAllNumber());
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int level = memberUserDO.getLevel();

		//goodsDto.setPostSize(goodsGoodsDO.getPostSize());



		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);


		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			map.put("postFee", goodsProductDO.getPostFee());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());

			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		/*Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}*/
		// 查询评论个数
		/*int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);*/

		// if("1".equals(params.get("spikeId").toString())){
		goodsDto.setRebateOne(isDefaultByGoods.getRebateOne());

		goodsDto.setStock(isDefaultByGoods.getStock());
		//预计收益
		String sharePrice ;

		switch (level) {//如果是0普通用户,1团长,2核心,3合伙人
			case 0:
				goodsDto.setPrice(isDefaultByGoods.getPrice());
				sharePrice="";
				break;
			case 1:
				goodsDto.setPrice(isDefaultByGoods.getPriceC());
				sharePrice ="￥"+ NumberUtil.div(RandomUtil.randomInt(1,9),100)+"~￥"+isDefaultByGoods.getPrice().subtract(isDefaultByGoods.getPriceC());
				break;
			case 2:
				goodsDto.setPrice(isDefaultByGoods.getPriceZ());
				sharePrice ="￥"+ NumberUtil.div(RandomUtil.randomInt(1,9),100)+"~￥"+isDefaultByGoods.getPrice().subtract(isDefaultByGoods.getPriceZ());
				break;
			case 3:
				goodsDto.setPrice(isDefaultByGoods.getPriceG());
				sharePrice ="￥"+ NumberUtil.div(RandomUtil.randomInt(1,9),100)+"~￥"+isDefaultByGoods.getPrice().subtract(isDefaultByGoods.getPriceG());
				break;
			default:
				goodsDto.setPrice(isDefaultByGoods.getPrice());
				sharePrice="";
				break;
		}

			//历史记录
		MemberFollowDO memberFollowDO = new MemberFollowDO();
		memberFollowDO.setGoodsId(goodsId);
		memberFollowDO.setId(UuidUtil.get32UUID());
		memberFollowDO.setCreateAt(new Date());
		memberFollowDO.setUserId(userId);
		memberFollowDao.save(memberFollowDO);

		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(goodsDto);
		stringObjectMap.put("video",goodsGoodsDO.getLive());
		stringObjectMap.put("spikeEnd",goodsGoodsDO.getSpikeEnd());
		stringObjectMap.put("level",level);
		stringObjectMap.put("sharePrice",sharePrice);
		stringObjectMap.put("priceMarket",isDefaultByGoods.getPriceMarket());
		stringObjectMap.put("hasSpec",goodsGoodsDO.getHasSpec());

		Map<String,Object> map =  goodsGoodsDao.getBaiFenBiByGoods(params);
		stringObjectMap.put("baiFenBi",map.get("baiFenBi"));
		stringObjectMap.put("stock", map.get("stock"));
		stringObjectMap.put("sale", map.get("sale"));
		stringObjectMap.put("sunMoney", isDefaultByGoods.getPrice());//晒单价
		return R.ok().put("data", stringObjectMap);
	}

	/**
	 * 秒杀商品详情页
	 */
	@Override
	public R getSpikeDetail(Map<String, Object> params) {
		String spikeId = params.get("spikeId").toString();
		GoodsSpikeDO goodsSpikeDO = goodsSpikeService.get(spikeId);
		GoodsSpikeTimeDO goodsSpikeTimeDO = goodsSpikeTimeDao.get(goodsSpikeDO.getTimeId());
		String goodsId = goodsSpikeDO.getGoodsId();
		params.put("goodsId", goodsId);
		// GoodsSpikeTimeDO goodsSpikeTimeDO =
		// goodsSpikeTimeDao.get(goodsSpikeDO.getTimeId());
		String userId = params.get("userId").toString();
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsProductDO isDefaultByGoods = goodsProductDao.getIsDefaultByGoods(goodsId);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setId(spikeId);
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsSpikeDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(1);
		SimpleDateFormat shiFormat = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat shisFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String today = shiFormat.format(new Date());
		try {
			goodsDto.setStartTime(shisFormat.parse(today + " " + goodsSpikeTimeDO.getStartAt().toString()));
			goodsDto.setEndTime(shisFormat.parse(today + " " + goodsSpikeTimeDO.getEndAt().toString()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		goodsDto.setIsvip(goodsGoodsDO.getIsvip());
		goodsDto.setCopywriting(goodsGoodsDO.getCopywriting());
		goodsDto.setAllNumber(goodsGoodsDO.getAllNumber());
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int level = memberUserDO.getLevel();
		int isvip = goodsGoodsDO.getIsvip();
		int postSize = goodsGoodsDO.getPostSize(); // 运费模板类型 0：通用运费，1：按模板 2:包邮
		if (postSize == 0) {
			goodsDto.setPostFee(goodsGoodsDO.getPostFee());
		}else{
			Map<String, Object> map = new HashMap<>();
			map.put("userId", userId);
			map.put("defaultValue", "0");
			List<MemberAddressDO> queryByUserId = memberAddressDao.queryByUserId(map);
			if(queryByUserId.size()>0){
				MemberAddressDO memberAddressDO = queryByUserId.get(0);
				MemberAddressDO memberAddress = memberAddressDao.get(memberAddressDO.getId());
				Map<String, Object> shopExpressMoneyMap = new HashMap<>();
				shopExpressMoneyMap.put("name", memberAddress.getProvince());
				shopExpressMoneyMap.put("delFlag", "0");
				List<ShopExpressMoneyDO> shopExpressMoneyList = shopExpressMoneyDao.likeList(shopExpressMoneyMap);
				BigDecimal postFee = null;
				if (shopExpressMoneyList.size() <= 0) {
					R.error("抱歉," + memberAddress.getProvince() + "地区不到!");
					// return
					// R.error("抱歉,"+memberAddress.getProvince()+"地区不到!");
				} else {
					
					Double weight = isDefaultByGoods.getWeight();
					// 总重量
					weight = weight * 1;
					// 向上取整
					Double ceil = Math.ceil(weight);
					int intWeight = ceil.intValue();
					if (intWeight <= shopExpressMoneyList.get(0).getFirstWeight()) {
						postFee = shopExpressMoneyList.get(0).getFirstPrice();
					} else {
						// 邮费=首重价格+续重价格*续重kg //续重价格 //总重量-首重重量
						postFee = shopExpressMoneyList.get(0).getFirstPrice()
								.add(shopExpressMoneyList.get(0).getAddPrice().multiply(
										new BigDecimal(intWeight - shopExpressMoneyList.get(0).getFirstWeight())));
					}

				}
				goodsDto.setPostFee(postFee);
				
			}
		}
		// MemberUserDO memberUserDO =
		// memberUserDao.get(params.get("userId").toString());
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsSpikeDO.getStock());
				goodsDto.setPrice(goodsSpikeDO.getPrice());

				/*
				 * BigDecimal weight = new
				 * BigDecimal(goodsProductDO.getWeight()).divide(new
				 * BigDecimal(100)); BigDecimal postFee =
				 * goodsProductDO.getPostFee(); if (postSize == 0) {
				 * goodsDto.setPostFee(postFee); } else { CmsContentDO contentDO
				 * = cmsContentDao.getByType("post-weight"); BigDecimal value =
				 * new BigDecimal(contentDO.getValue()); postFee =
				 * value.multiply(weight); goodsDto.setPostFee(postFee); }
				 */
				if (isvip == 0) {
					goodsDto.setMinePrice(goodsSpikeDO.getPrice());
				} else {
					switch (level) {
					case 1:
						goodsDto.setMinePrice(goodsSpikeDO.getPriceC());
						break;
					case 2:
						goodsDto.setMinePrice(goodsSpikeDO.getPriceZ());
						break;
					case 3:
						goodsDto.setMinePrice(goodsSpikeDO.getPriceG());
						break;
					default:
						goodsDto.setMinePrice(goodsSpikeDO.getPrice());
					}
				}
			}
		}

		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			// map.put("price_market", goodsProductDO.getPriceMarket());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			if (isvip == 0) {
				map.put("price", goodsSpikeDO.getPrice());
			} else {
				switch (level) {
				case 1:
					map.put("price", goodsSpikeDO.getPriceC());
					break;
				case 2:
					map.put("price", goodsSpikeDO.getPriceZ());
					break;
				case 3:
					map.put("price", goodsSpikeDO.getPriceG());
					break;
				default:
					map.put("price", goodsSpikeDO.getPrice());
				}
			}
			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}
		// 查询评论个数
		int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);
		return R.ok().put("data", goodsDto);
	}

	/**
	 * 会员专区商品详情页
	 */
	@Override
	public R getUpgradeDetail(Map<String, Object> params) {
		String upgradeId = params.get("upgradeId").toString();
		String userId = params.get("userId").toString();
		GoodsUpgradeDO goodsUpgradeDO = goodsUpgradeDao.get(upgradeId);
		String goodsId = goodsUpgradeDO.getGoodsId();
		params.put("goodsId", goodsId);
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setId(upgradeId);
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsUpgradeDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(5);

		goodsDto.setIsvip(goodsGoodsDO.getIsvip());
		goodsDto.setCopywriting(goodsGoodsDO.getCopywriting());
		goodsDto.setAllNumber(goodsGoodsDO.getAllNumber());
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int postSize = goodsGoodsDO.getPostSize(); // 运费模板类型 0：自定义运费，1：按重量模板

		// MemberUserDO memberUserDO =
		// memberUserDao.get(params.get("userId").toString());
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsUpgradeDO.getStock());
				goodsDto.setPrice(goodsProductDO.getPrice());
				goodsDto.setMinePrice(goodsUpgradeDO.getPrice());
				BigDecimal weight = new BigDecimal(goodsProductDO.getWeight()).divide(new BigDecimal(100));
				BigDecimal postFee = goodsProductDO.getPostFee();
				if (postSize == 0) {
					goodsDto.setPostFee(postFee);
				} else {
					CmsContentDO contentDO = cmsContentDao.getByType("post-weight");
					BigDecimal value = new BigDecimal(contentDO.getValue());
					postFee = value.multiply(weight);
					goodsDto.setPostFee(postFee);
				}
			}
		}

		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			// map.put("price_market", goodsProductDO.getPriceMarket());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			map.put("price", goodsUpgradeDO.getPrice());
			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}
		// 查询评论个数
		int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);
		return R.ok().put("data", goodsDto);
	}

	/**
	 * 拼团专区商品详情页
	 */
	@Override
	public R getTeamDetail(Map<String, Object> params) {
		String teamId = params.get("teamId").toString();
		String userId = params.get("userId").toString();
		GoodsTeamDO goodsTeamDO = goodsTeamDao.get(teamId);
		String goodsId = goodsTeamDO.getGoodsId();
		params.put("goodsId", goodsId);
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setId(teamId);
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsTeamDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(4);
		goodsDto.setIsvip(goodsGoodsDO.getIsvip());
		goodsDto.setCopywriting(goodsGoodsDO.getCopywriting());
		goodsDto.setAllNumber(goodsGoodsDO.getAllNumber());
		goodsDto.setNumber(goodsTeamDO.getNumber());
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int level = memberUserDO.getLevel();
		int isvip = goodsGoodsDO.getIsvip();
		int postSize = goodsGoodsDO.getPostSize(); // 运费模板类型 0：自定义运费，1：按重量模板 2包邮
		if (postSize == 0) {
			goodsDto.setPostFee(goodsGoodsDO.getPostFee());
		}
		// MemberUserDO memberUserDO =
		// memberUserDao.get(params.get("userId").toString());
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsTeamDO.getStock());
				goodsDto.setPrice(goodsTeamDO.getPrice());
				BigDecimal weight = new BigDecimal(goodsProductDO.getWeight()).divide(new BigDecimal(100));
				BigDecimal postFee = goodsProductDO.getPostFee();
				if (postSize == 0) {
					goodsDto.setPostFee(postFee);
				} else {
					CmsContentDO contentDO = cmsContentDao.getByType("post-weight");
					BigDecimal value = new BigDecimal(contentDO.getValue());
					postFee = value.multiply(weight);
					goodsDto.setPostFee(postFee);
				}
				if (isvip == 0) {
					goodsDto.setMinePrice(goodsTeamDO.getPrice());
				} else {
					switch (level) {
					case 1:
						goodsDto.setMinePrice(goodsTeamDO.getPriceC());
						break;
					case 2:
						goodsDto.setMinePrice(goodsTeamDO.getPriceZ());
						break;
					case 3:
						goodsDto.setMinePrice(goodsTeamDO.getPriceG());
						break;
					default:
						goodsDto.setMinePrice(goodsTeamDO.getPrice());
					}
				}
			}
		}

		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			// map.put("price_market", goodsProductDO.getPriceMarket());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			if (isvip == 0) {
				map.put("price", goodsTeamDO.getPrice());
			} else {
				switch (level) {
				case 1:
					map.put("price", goodsTeamDO.getPriceC());
					break;
				case 2:
					map.put("price", goodsTeamDO.getPriceZ());
					break;
				case 3:
					map.put("price", goodsTeamDO.getPriceG());
					break;
				default:
					map.put("price", goodsTeamDO.getPrice());
				}
			}
			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}
		// 查询评论个数
		int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);
		return R.ok().put("data", goodsDto);
	}

	/**
	 * 9.9专区商品详情页
	 */
	@Override
	public R getNineDetail(Map<String, Object> params) {
		String nineId = params.get("nineId").toString();
		String userId = params.get("userId").toString();
		GoodsNineDO goodsNineDO = goodsNineDao.get(nineId);
		String goodsId = goodsNineDO.getGoodsId();
		params.put("goodsId", goodsId);
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setId(nineId);
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsNineDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(2);

		// MemberUserDO memberUserDO =
		// memberUserDao.get(params.get("userId").toString());
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsNineDO.getStock());
				goodsDto.setPrice(goodsProductDO.getPrice());
				goodsDto.setPostFee(goodsProductDO.getPostFee());
				goodsDto.setMinePrice(goodsNineDO.getPrice());
			}
		}

		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			// map.put("price_market", goodsProductDO.getPriceMarket());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			map.put("price", goodsNineDO.getPrice());
			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}
		// 查询评论个数
		int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);
		return R.ok().put("data", goodsDto);
	}

	/**
	 * 砍价商品详情页
	 */
	@Override
	public R getBargainDetail(Map<String, Object> params) {
		String bargainId = params.get("bargainId").toString();
		String userId = params.get("userId").toString();
		GoodsBargainDO goodsBargainDO = goodsBargainDao.get(bargainId);
		String goodsId = goodsBargainDO.getGoodsId();
		params.put("goodsId", goodsId);
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params);
		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);
		goodsGoodsDO.setGoodsProductList(goodsProductList);
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params);
		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setId(bargainId);
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsBargainDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(3);

		// MemberUserDO memberUserDO =
		// memberUserDao.get(params.get("userId").toString());
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsBargainDO.getStock());
				goodsDto.setPrice(goodsProductDO.getPrice());
				goodsDto.setPostFee(goodsProductDO.getPostFee());
				goodsDto.setMinePrice(goodsBargainDO.getPrice());
			}
		}

		List<String> bannerList = new ArrayList<>();
		List<String> goodsImgList = new ArrayList<>();

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			// map.put("price_market", goodsProductDO.getPriceMarket());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numNale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			map.put("price", goodsBargainDO.getPrice());
			productList.add(map);
		}
		goodsDto.setProductList(productList);
		// 是否关注
		Map<String, Object> searchMap = new HashMap<String, Object>();
		searchMap.put("goodsId", goodsId);
		searchMap.put("userId", userId);
		List list = memberFollowDao.list(searchMap);
		if (list.size() == 0) {
			goodsDto.setisFollow(false);
		} else {
			goodsDto.setisFollow(true);
		}
		// 查询评论个数
		int comentSize = orderComentDao.getComentByGoods(params).size();
		goodsDto.setComentSize(comentSize);
		return R.ok().put("data", goodsDto);
	}

	private void removePrice(Map<String, Object> map) {
		map.remove("price_f");
		map.remove("price_l");
		map.remove("price_h");

	}

	/*
	 * @Override public R getGroupGoods(Map<String, Object> params) {
	 * PageHelperUtils.page(params); List<Map<String, Object>> goodsList =
	 * goodsGoodsDao.getGroupGoods(params); MemberUserDO memberUserDO =
	 * memberUserDao.get(params.get("userId").toString()); for (Map<String,
	 * Object> map : goodsList) {
	 * 
	 * if(memberUserDO.getLevel()==0){ map.put("price", map.get("price_f"));
	 * }else if (memberUserDO.getLevel()==1){ map.put("price",
	 * map.get("price_h")); }else if (memberUserDO.getLevel()==2){
	 * map.put("price", map.get("price_l")); } removePrice(map); }
	 * PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goodsList);
	 * 
	 * return R.ok().put("data", pageInfo); }
	 */

	/*
	 * @Override public R getSpike(Map<String, Object> params) {
	 * PageHelperUtils.page(params); List<Map<String, Object>> goodsList =
	 * goodsGoodsDao.getSpike(); MemberUserDO memberUserDO =
	 * memberUserDao.get(params.get("userId").toString()); for (Map<String,
	 * Object> map : goodsList) {
	 * 
	 * if(memberUserDO.getLevel()==0){ map.put("price", map.get("price_f"));
	 * }else if (memberUserDO.getLevel()==1){ map.put("price",
	 * map.get("price_h")); }else if (memberUserDO.getLevel()==2){
	 * map.put("price", map.get("price_l")); } removePrice(map); }
	 * 
	 * PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goodsList);
	 * return R.ok().put("data", pageInfo); }
	 */

	/**
	 * 热卖、推荐商品列表
	 */
	@Override
	public R recommend(Map<String, Object> params) {
		/*String userId = com.bootdo.common.utils.StringUtils.getString(params.get("userId"));
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int level = 0;*/
		/*
		 * if (memberUserDO != null) { params.put("level",
		 * memberUserDO.getLevel()); level = memberUserDO.getLevel(); } else {
		 * params.put("level", 4); level = 4; }
		 */
		PageHelperUtils.page(params);
		List<Map<String, Object>> goodsList = goodsGoodsDao.recommend(params);
		for (Map<String, Object> goodsMap : goodsList) {
			//int isvip = Integer.valueOf(goodsMap.get("isvip").toString());
			String imgurl = goodsMap.get("imgurl").toString();
			List<String> imgList = new ArrayList<String>();
			imgList.add(imgurl);
			goodsMap.remove("imgurl");
			goodsMap.put("imgList", imgList);
			Object price = goodsMap.get("price");
			/*Object price_c = goodsMap.get("price_c");
			Object price_z = goodsMap.get("price_z");
			Object price_g = goodsMap.get("price_g");*/
			//if (isvip == 0) {
				goodsMap.put("minePrice", price);
			/*} else {
				switch (level) {
				case 1:
					goodsMap.put("minePrice", price_c);
					break;
				case 2:
					goodsMap.put("minePrice", price_z);
					break;
				case 3:
					goodsMap.put("minePrice", price_g);
					break;
				default:
					goodsMap.put("minePrice", price);
				}
			}*/
		}
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(goodsList);
		return R.ok().put("data", pageInfo);
	}

	@Override
	public Map<String, Object> getCmsGoods(Map<String, Object> params) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> nineList = goodsNineDao.getNineGoodsList(params);
		List<Map<String, Object>> apikeList = goodsSpikeDao.getGoodsByTime(params);
		List<Map<String, Object>> hotList = goodsGoodsDao.getHotList(params);
		map.put("nineList", nineList);
		map.put("spikeList", apikeList);
		map.put("hotList", hotList);
		return map;
	}

	@Override
	public R isCanBye(Map<String, Object> params) {
		String productId = params.get("productId").toString();
		String xId = params.get("xId").toString(); // goodsId\ nineId\ spikeId
		int num = Integer.valueOf(params.get("num").toString());
		int type = Integer.valueOf(params.get("type").toString()); //0普通商品
		GoodsProductDO product = goodsProductService.get(productId);
		GoodsGoodsDO goodsDO = goodsGoodsDao.get(product.getGoodsId());
		int p_disabled = product.getDisabled();
		int p_del = product.getDelFlag();
		int g_del = goodsDO.getDelFlag();
		int g_disabled = goodsDO.getDisabled();
		// String vipLevel = goodsDO.getVipLevel(); //商品允许等级
		// int allNumber = goodsDO.getAllNumber(); //商品限购量

		if (p_del == 1 || p_disabled == 1 || g_del == 1 || g_disabled == 1) {
			return R.error(2, "该商品已下架");
		}
		if (num == 0) {
			return R.error(1, "商品数量不能为0");
		}
		int min = product.getBuyMin();
		int max = product.getBuyMax();
		if (num < min) {
			return R.error(1, "该商品最小购买量为" + min);
		} else if (num > max) {
			return R.error(1, "该商品最大购买量为" + max);
		}
		// 判断是否有资格购买
		/*
		 * if (type != 4 && vipLevel.indexOf(level+"") == -1) { return
		 * R.error(3,"该商品您没有权限购买"); }
		 */
		// 判断商品限购数量
		/*
		 * Map map = new HashMap<String,Object>(); map.put("userId",userId);
		 * map.put("goodsId",goodsDO.getId()); int canBye = allNumber -
		 * goodsGoodsDao.getSumByUser(map); if (num > canBye) { return
		 * R.error(4,"此商品已达到限购数量"); }
		 */
		// 判断库存
		int stock = product.getStock(); // 库存
		if (stock < num) {
			return R.error(5, "商品库存不足");
		}
		// 判断该商品是否存在
		if(type == 0 ){
			GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.get(xId);
			if(goodsGoodsDO == null){
				return R.error("商品不存在");
		}
		}
		//判断收获地址是否存在
		/*String address_id = params.get("address_id").toString();
		MemberAddressDO memberAddressDO = memberAddressDao.get(address_id);
		if(memberAddressDO == null){
			return R.error("收货地址不存在");
		}*/
		if (type == 2) { // 秒杀商品
			GoodsSpikeDO spikeDO = goodsSpikeDao.get(xId);
			int spikeNum = spikeDO.getStock();
			if (spikeNum < num) {
				return R.error("该秒杀商品库存不足");
			}
			// 判断秒杀时间
			String timeId = spikeDO.getTimeId();
			GoodsSpikeTimeDO goodsSpikeTimeDO = goodsSpikeTimeDao.get(timeId);
			SimpleDateFormat shiFormat = new SimpleDateFormat("HH:mm");
			Date startAt = null;
			Date endAt = null;
			Date now = null;
			try {
				now = shiFormat.parse(shiFormat.format(new Date()).toString());
				startAt = shiFormat.parse(goodsSpikeTimeDO.getStartAt().toString());
				endAt = shiFormat.parse(goodsSpikeTimeDO.getEndAt().toString());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			if (startAt.after(now)) {
				return R.error("该商品秒杀还没开始");
			}
			if (!endAt.after(now)) {
				return R.error("该商品秒杀已结束");
			}

		}
		/*
			 * else if (type == 1) { //9.9商品 GoodsNineDO nineDO =
			 * goodsNineDao.get(xId); int nineNum = nineDO.getStock(); if
			 * (nineNum < num) { return R.error("该专区商品库存不足"); } } else if (type
			 * == 4) { //拼团商品 GoodsTeamDO teamDO = goodsTeamDao.get(xId); int
			 * teamNum = teamDO.getStock(); if (teamNum < num) { return
			 * R.error("该专区商品库存不足"); } if (num != 1) { return
			 * R.error("该专区商品一次只能买一件"); } } else if (type == 5) { //会员商品
			 * GoodsUpgradeDO upgradeDO = goodsUpgradeDao.get(xId); int
			 * upgradeNum = upgradeDO.getStock(); if (upgradeNum < num) { return
			 * R.error("该专区商品库存不足"); } int goodsLevel = upgradeDO.getLevel(); if
			 * (!(goodsLevel>level)) { return R.error("您已经升级过该会员了"); } if (num
			 * != 1) { return R.error("该专区商品一次只能买一件"); } }else if (type == 6) {
			 * //积分商品 Map<String, Object> scoreMap = new HashMap<>();
			 * scoreMap.put("userId", userId); BigDecimal sumByUser =
			 * memberScoreDao.getSumByUser(scoreMap);
			 * if(product.getPrice().compareTo(sumByUser)==-1){ return
			 * R.error("积分不够,无法兑换!"); } }
			 */
		return R.ok();
	}

	/* 获取后台商品列表 */
	public List<Map<String, Object>> getList(Map<String, Object> map) {
		return goodsGoodsDao.getList(map);
	}

	/**
	 * 搜索-热销榜
	 * @return
	 */
	@Override
	public PageInfo<Map<String, Object>> geToptList(Map<String, Object> params) {
		PageHelperUtils.page(params);
		List<Map<String,Object>> list = goodsSpikeDao.geToptList(params);
		for (Map<String, Object> map : list) {
			int stock = (int) map.get("stock");
			int num_sale = (int) map.get("num_sale");
			int baiFenBi = (num_sale *100)/stock ;//百分比
			map.put("baiFenBi",baiFenBi);
		}
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}


	/**
	 * 普通商品详情
	 */
	@Override
	public R getGoodsDetail(Map<String, Object> params) {
		String goodsId = params.get("goodsId").toString();
		String userId = params.get("userId").toString();
		GoodsGoodsDO goodsGoodsDO = goodsGoodsDao.getDetail(params); //根据商品id查寻商品

		List<GoodsProductDO> goodsProductList = goodsProductDao.getGoodsByGoodsId(params);//根据商品id查寻该产品所有规格
		GoodsProductDO isDefaultByGoods = goodsProductDao.getIsDefaultByGoods(goodsId); //找到这个商品所属的规格

		goodsGoodsDO.setGoodsProductList(goodsProductList); //关联的货品
		List<GoodsImagesDO> goodsImagesList = goodsImagesDao.getGoodsImgs(params); //拿到该产品的 轮播图

		GoodsDto goodsDto = new GoodsDto();
		goodsDto.setGoodsId(goodsGoodsDO.getId());
		goodsDto.setName(goodsGoodsDO.getName());
		goodsDto.setNote(goodsGoodsDO.getNote());
		goodsDto.setNumSale(goodsGoodsDO.getNumSale());
		goodsDto.setParam(goodsGoodsDO.getParam());
		goodsDto.setSpec(goodsGoodsDO.getSpec());
		goodsDto.setTitle(goodsGoodsDO.getTitle());
		goodsDto.setImgurl(goodsGoodsDO.getImgurl());
		goodsDto.setCategory(0);
		goodsDto.setCopywriting(goodsGoodsDO.getCopywriting());
		goodsDto.setAllNumber(goodsGoodsDO.getAllNumber());
		goodsDto.setPostSize(goodsGoodsDO.getPostSize());

		// if("1".equals(params.get("spikeId").toString())){
		BigDecimal priceMarket =new BigDecimal("0.00");
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			if (goodsProductDO.getIsDefault() == 1) {
				goodsDto.setStock(goodsProductDO.getStock());
				priceMarket = goodsProductDO.getPriceMarket();
				goodsDto.setPrice(goodsProductDO.getPrice());

			}
		}

		List<String> bannerList = new ArrayList<>(); //轮播图的集合
		List<String> goodsImgList = new ArrayList<>(); //商品详情的集合

		for (GoodsImagesDO goodsImagesDO : goodsImagesList) {
			if (goodsImagesDO.getAddress() == 0) {
				bannerList.add(goodsImagesDO.getImgurl());
			} else if (goodsImagesDO.getAddress() == 1) {
				goodsImgList.add(goodsImagesDO.getImgurl());
			}
		}
		goodsDto.setBanner(bannerList);
		goodsDto.setGoodsImg(goodsImgList);

		/*// 货品信息
		List<Map<String, Object>> productList = new ArrayList<>();
		// if("1".equals(params.get("spikeId").toString())){
		for (GoodsProductDO goodsProductDO : goodsProductList) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", goodsProductDO.getName());
			map.put("icon", goodsProductDO.getIcon());
			map.put("spec", goodsProductDO.getSpec());
			map.put("postFee", goodsProductDO.getPostFee());
			map.put("stock", goodsProductDO.getStock());
			map.put("unit", goodsProductDO.getUnit());
			map.put("numSale", goodsProductDO.getNumSale());
			map.put("id", goodsProductDO.getId());
			productList.add(map);
		}
		goodsDto.setProductList(productList);*/
		// 是否关注


		//根据用户id和商品id往足迹表里插入一条数据
		Map<String,Object> query = new HashMap<>();
		query.put("userId",userId);
		query.put("goodsId",goodsId);
		List<MemberFollowDO> list = memberFollowDao.list(query);
		if(list.size() == 0 ){
			MemberFollowDO mf = new MemberFollowDO() ;
			mf.setId(IdUtil.simpleUUID());
			mf.setGoodsId(goodsId);
			mf.setUserId(userId);
			mf.setCreateAt(new Date());
			memberFollowDao.save(mf);
		}else {
			list.get(0).setCreateAt(new Date());
			memberFollowDao.update(list.get(0));
		}

		//获取当前对象的身份及分享可赚金额
		Map<String, Object> map = BeanUtil.beanToMap(goodsDto);
		MemberUserDO memberUserDO = memberUserDao.get(userId); //获取user对象
		int level = memberUserDO.getLevel(); //拿到对象身份
		BigDecimal userPrice = new BigDecimal(0.00);
		BigDecimal price = new BigDecimal(0.00);
		BigDecimal result = new BigDecimal(0.00);
		String sharePrice ;
		switch (level) {//如果是0普通用户,1团长,2核心,3合伙人
			case 0:
				map.put("share","0");
				map.put("level",level);
				map.put("levelPrice",isDefaultByGoods.getPrice());

				break;
			case 1:
				userPrice = isDefaultByGoods.getPrice();
				price = isDefaultByGoods.getPriceC();
				result = userPrice.subtract(price);
				sharePrice = "￥1~￥"+result;
				map.put("sharePrice",sharePrice);
				map.put("level",level);
				map.put("levelPrice",isDefaultByGoods.getPriceC());
				break;
			case 2:
				userPrice = isDefaultByGoods.getPrice();
				price = isDefaultByGoods.getPriceZ();
				result = userPrice.subtract(price);
				sharePrice = "￥1~￥"+result;
				map.put("sharePrice",sharePrice);
				map.put("level",level);
				map.put("levelPrice",isDefaultByGoods.getPriceZ());
				break;
			case 3:
				userPrice = isDefaultByGoods.getPrice();
				price = isDefaultByGoods.getPriceG();
				result = userPrice.subtract(price);
				sharePrice = "￥1~￥"+result;
				map.put("sharePrice",sharePrice);
				map.put("level",level);
				map.put("levelPrice",isDefaultByGoods.getPriceG());
				break;
		}
		map.put("priceMarket",priceMarket);
		String live = goodsGoodsDao.getLiveById(goodsId);
		map.put("video",live);
		return R.ok().put("data", map);
	}


	/**
	 * 普通商品详情-热销推荐
	 * @param params pageSize , pageNumber
	 * @return
	 */
	@Override
	public PageInfo<Map<String, Object>> recommendGoodsList(Map<String, Object> params) {
		PageHelperUtils.page(params);
		List<Map<String,Object>> list = goodsGoodsDao.gerecommendGoodsList(params);
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	/**
	 * 普通商品详情-售后须知
	 * @return
	 */
	@Override
	public String getAfterNotice() {
		String afterNotice =goodsGoodsDao.getAfterNotice();
		return afterNotice;
	}

    @Override
    public int countList(Map<String, Object> map) {
		int count =goodsGoodsDao.countList(map);
		return count;

    }

	/**
	 * 直播列表
	 * @param paramMap pageSize每页条数 pageNum当前页数
	 * @return
	 */
	@Override
	public PageInfo<Map<String, Object>> getLiveGoods(Map<String, Object> paramMap) {
		PageHelperUtils.page(paramMap);
		List<Map<String,Object>> list = goodsGoodsDao.getLiveGoods(paramMap);
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	/**
	 * 预约直播
	 * @param paramMap pageSize每页条数 pageNum当前页数
	 * @return
	 */
	@Override
	public PageInfo<Map<String, Object>> getAppointmentLiveList(Map<String, Object> paramMap) {
		PageHelperUtils.page(paramMap);
		List<Map<String,Object>> list = goodsGoodsDao.getAppointmentLiveList(paramMap);
		for (Map<String, Object> stringObjectMap : list) {
			String date = (String) stringObjectMap.get("star_at");
			String star_at = date+"开播";
			stringObjectMap.put("star_at",star_at);

			Map<String,Object> map = new HashMap<>();
			map.put("liveId",stringObjectMap.get("id"));
			map.put("userId",paramMap.get("userId"));

			if(!paramMap.containsKey("userId") || com.bootdo.common.utils.StringUtils.isBlank(paramMap.get("userId").toString())
			){
				stringObjectMap.put("appointment","预约");
			}else {
				int count = goodsLiveAppointmentDao.count(map);
				if(count > 0){
					stringObjectMap.put("appointment","已经预约");
				}else {
					stringObjectMap.put("appointment","预约");
				}
			}

		}
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	/**
	 * 预约直播按钮
	 * @param param
	 * @return
	 */
	@Override
	public R addAppointmen(Map<String, Object> param) {
		int count = goodsLiveAppointmentDao.count(param);
		if(count > 0){
			return R.ok(1,"已经预约");
		}
		GoodsLiveAppointmentDO goodsLiveAppointmentDO = new GoodsLiveAppointmentDO();
		goodsLiveAppointmentDO.setId(UUIDUtils.getUUID());
		goodsLiveAppointmentDO.setUserId(param.get("userId").toString());
		goodsLiveAppointmentDO.setLiveId(param.get("liveId").toString());
		goodsLiveAppointmentDO.setCaAt(new Date());
		goodsLiveAppointmentDO.setUpAt(new Date());
		goodsLiveAppointmentDO.setDelFlag(0);
		goodsLiveAppointmentDao.save(goodsLiveAppointmentDO);
		return R.ok();
	}

}
